package com.mmcb.utils;

import com.alibaba.fastjson.JSON;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import reactor.core.publisher.Mono;

/**
 * 作者：李嘉浩
 * 时间：2024-08-24-9:58
 * 功能：
 */
public class ResponseUtil {
    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String s) {
        response.setStatusCode(HttpStatus.OK);
        response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf8");
        R result = R.error().code(HttpStatus.UNAUTHORIZED.value()).message(s);
        DataBuffer dataBuffer = response.bufferFactory().wrap(JSON.toJSONString(result).getBytes());
        return response.writeWith(Mono.just(dataBuffer));

    }
}
